// 商品列表逻辑代码
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { findSubCategoryGoods } from '@/api/category'
export function useGoodsList () {
  const route = useRoute()
  // 基础商品数据渲染
  const goodsListRef = ref([])
  // 准备请求参数
  const reqParams = {
    page: 1,
    pageSize: 20,
    categoryId: route.params.id,
    sortField: null, // 排序类别
    attrs: [], // 商品属性
    brandId: null // 品牌名称
  }
  async function loadGoodsList () {
    const res = await findSubCategoryGoods(reqParams)
    goodsListRef.value = res.data.result.items
  }
  onMounted(() => {
    loadGoodsList()
  })

  return {
    goodsListRef,
    reqParams,
    loadGoodsList
  }
}
